<?php
use OSS\OssClient;

require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/Lib/Base.php';
require_once __DIR__ . '/funcs.php';
require_once __DIR__ . '/Lib/Page.php';

checkLogin();
checkFunc(5);

$now = time();
$success = $_GET['success'] ?? null;
$error = $_GET['error'] ?? null;
$action = $_GET['action'] ?? null;

display_header();

$version_log = $DB->select('game_version_log', '*', ['ORDER'=>['id'=>'DESC']]);

?>

<link href="css/jquery.dm-uploader.min.css" rel="stylesheet">
<style>
    #logtable tbody tr td{
        text-align:left;
        font-size:16px;
        vertical-align:middle;
    }
    textarea{
        width: 320px;
        height: 600px;
    }
    .pre{
        display: none;
    }
</style>
<section class="content">
    <?php if($error) : ?>
        <div class="alert alert-warning alert-dismissible">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
            <span><?php echo $error; ?></span>
        </div>
    <?php endif ?>
    <?php if($success) : ?>
        <div class="alert alert-success alert-dismissible">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
            <h4><i class="icon fa fa-check"></i> 成功</h4>
            <?php echo $success; ?>
        </div>
    <?php endif ?>

    <div class="box box-primary">
        <div class="box-header with-border">
            <h3 class="box-title"><i class="fa fa-search"></i> 修改明细</h3>
        </div>

        <div class="box-body" id="vbody">

            <table id="logtable" class="table table-bordered table-striped dataTable table-hover " role="grid" aria-describedby="example1_info">
                <thead>
                <tr>
                    <th class="" rowspan="1" colspan="1" width="80" style="text-align:center">ID</th>
                    <th class="" rowspan="1" colspan="1" width="150">菜单</th>
                    <th class="" rowspan="1" colspan="1" width="150">模块</th>
                    <th class="" rowspan="1" colspan="1" width="150">操作类型</th>
                    <th class="" rowspan="1" colspan="1" width="150">数据差异</th>
                    <th class="" rowspan="1" colspan="1" width="150">操作时间</th>
                </tr>
                </thead>
                <tbody>
                <?php if(!empty($version_log)) { foreach($version_log as $item) { ?>
                    <tr role="row" style="text-align:center;">
                        <td class="item_id"><?php echo $item['id']; ?></td>
                        <td><?php echo $item['module']; ?></td>
                        <td ><?php echo $item['action']; ?></td>
                        <td><?php
                            if ($item['type'] == 'add') echo '新增';
                            elseif($item['type'] == 'edit') echo '修改';
                            elseif($item['type'] == 'off') echo '下架';
                            elseif($item['type'] == 'on') echo '上架';
                            elseif($item['type'] == 'del') echo '删除';
                            ?>
                        </td>
                        <td class="left" style="padding:0;padding-left:15px;">
                            <pre class="pre" id="pre_data"><?php print_r(json_decode($item['data'],true)) ?></pre>
                            <pre class="pre" id="pre_data_to"><?php print_r(json_decode($item['data_to'],true)) ?></pre>
                            <button class="btn btn-primary btn-sm open_data">查看数据差异</button>
                        </td>
                        <td><?php echo date('Y-m-d H:i:s',$item['create_time']); ?></td>
                    </tr>
                <?php } } ?>
                </tbody>
            </table>

            <!-- 添加兑换类型 -->
            <div class="modal fade" id="modal-add-admin">
                <div class="modal-dialog modal-lg">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title"></h4>
                            </div>
                            <div class="modal-body">
                                <div style="display: inline-block">
                                    <span>原数据</span>
                                    <textarea id="text_data" name="" cols="30" rows="10"></textarea>
                                </div>
                                <div style="display: inline-block">
                                    <span>操作后数据</span>
                                    <textarea id="text_data_to" name="" cols="30" rows="10"></textarea>
                                </div>
                            </div>
                        </div>
                </div>
            </div>

        </div>

    </div>
</section>

<!-- jQuery 3 -->
<script src="js/jquery.min.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src="js/pace.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Select2 -->
<script src="bower_components/select2/dist/js/select2.full.min.js"></script>
<!-- InputMask -->
<script src="plugins/input-mask/jquery.inputmask.js"></script>
<script src="plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="plugins/input-mask/jquery.inputmask.extensions.js"></script>

<script src="js/jquery.dm-uploader.min.js"></script>

<script type="text/javascript">

    $(function() {
        $('.open_data').click(function() {
            var id = $(this).parent().parent().find('.item_id').text();
            $('.modal-title').text('id' + id + '- 数据差异');
            var data = $(this).parent().parent().find('#pre_data').html();
            var data_to = $(this).parent().parent().find('#pre_data_to').html();
            $('#text_data').html(data);
            $('#text_data_to').html(data_to);
            $('#modal-add-admin').modal({
                backdrop: 'static',
            });
        });

        setTimeout(function() {
            $('.alert-success').fadeOut();
            if($('.alert-warning').find('span').html() && $('.alert-warning').find('span').html().length < 60) {
                $('.alert-warning').fadeOut();
            }
        }, 2000);
    });
</script>

</body>
</html>

